package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.huifaapp.mall.R;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.bean.JDcomHotlistBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by duanyu on 2018/1/29.
 */

public class Tmall_homepage_cehuaAdapter extends RecyclerView.Adapter<Tmall_homepage_cehuaAdapter.ViewHolder>implements View.OnClickListener {
    private List<JDcomHotlistBean.DataBean.ListBean>list;
    private Context context;

    public Tmall_homepage_cehuaAdapter(List<JDcomHotlistBean.DataBean.ListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View recyclerViewItemfootView = LayoutInflater.from(context).inflate(R.layout.itme_homepcehua,parent,false);
        recyclerViewItemfootView.setOnClickListener(this);
        return new ViewHolder(recyclerViewItemfootView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Picasso.with(context).load(list.get(position).getMainImageUrl()).into(holder.image1);
        holder. title1.setText("\t\t\t\t\t"+list.get(position).getGoodsName());
        holder. itme_homepcehua_yuanjia.setText("¥ "+list.get(position).getPrice());
        holder.itme_homepcehua_xainjian.setText("降"+list.get(position).getCouponMoney()+"元");
        holder.itme_homepcehua_yiqiang.setText("已抢"+list.get(position).getTotalSales()+"件");
//        if(list.get(position).getCouponMoney().equals("0.0")||list.get(position).getCouponMoney().equals("0.00")){
//            holder.itme_homepcehua_youhuijuan.setVisibility(View.GONE);
//        }else{
            holder.itme_homepcehua_youhuijuan.setVisibility(View.VISIBLE);
            holder.itme_homepcehua_youhuijuan.setText("¥"+list.get(position).getConPrice());
//        }
        if(SPUtils.getInstance().getString(SPConstants.KEY_ISSTORE).equals("1")){
            holder.itme_homepcehua_yongjing.setVisibility(View.VISIBLE);
        }else{
            holder.itme_homepcehua_yongjing.setVisibility(View.GONE);
        }
        holder.itme_homepcehua_yongjing.setText("赚"+list.get(position).getWlCommission()+"");
        holder.itme_homepcehua_yuanjia.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onClick(View v) {
        if (mMyItemclickListener != null) {
            mMyItemclickListener.itemclick(v, (Integer) v.getTag());
        }
    }
    public interface MyItemclickListener {
        void itemclick(View view, int position);


    }
    public MyItemclickListener mMyItemclickListener;

    public void setmMyItemclickListener(MyItemclickListener mMyItemclickListener) {
        this.mMyItemclickListener = mMyItemclickListener;
    }
    class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView image1;
        private final TextView title1;
        private final TextView itme_homepcehua_yuanjia;
        private final TextView itme_homepcehua_yiqiang;
        private final TextView itme_homepcehua_xainjian;
        private final TextView itme_homepcehua_youhuijuan;
        private final TextView itme_homepcehua_yongjing;

        public ViewHolder(View itemView) {
            super(itemView);
            image1 = (ImageView) itemView.findViewById(R.id.show_imageh1);
            title1 = (TextView)itemView.findViewById(R.id.show_image1_title);
            itme_homepcehua_yuanjia = (TextView)itemView.findViewById(R.id.itme_homepcehua_yuanjia);
            itme_homepcehua_xainjian = (TextView)itemView.findViewById(R.id.itme_homepcehua_xainjian);
            itme_homepcehua_yiqiang = (TextView)itemView.findViewById(R.id.itme_homepcehua_yiqiang);
            itme_homepcehua_youhuijuan = (TextView) itemView.findViewById(R.id.itme_homepcehua_youhuijuan);
            itme_homepcehua_yongjing = (TextView) itemView.findViewById(R.id.itme_homepcehua_yongjing);
        }
    }
}
